package graph.group.zhangtao.guider.homepage.adapters;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import graph.group.zhangtao.guider.R;
import graph.group.zhangtao.guider.homepage.content.SpotItem;

/**
 * Created by T5 on 2018/3/26.
 */

public class SpotItemAdapter extends ArrayAdapter<SpotItem> {

    private int resourceId;

    public SpotItemAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull List<SpotItem> objects) {
        super(context, resource, textViewResourceId, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        SpotItem spotItem = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);

        ImageView spotImage = view.findViewById(R.id.iv_spot);
        TextView spotName = view.findViewById(R.id.tv_spot_name);
        TextView spotDesc = view.findViewById(R.id.tv_spot_desc);

        spotImage.setImageResource(spotItem.getSpotImageId());
        spotName.setText(spotItem.getSpotName());
        spotDesc.setText(spotItem.getSpotDesc());
        return view;
    }
}
